import { keysOf } from "../../defines/allapps";

export const presets: {
  [key: string]: { color?: GPUBlendComponent; alpha?: GPUBlendComponent };
} = {
  "default (copy)": {
    color: {
      operation: "add",
      srcFactor: "one",
      dstFactor: "zero",
    },
  },
  "premultiplied blend (source-over)": {
    color: {
      operation: "add",
      srcFactor: "one",
      dstFactor: "one-minus-src-alpha",
    },
  },
  "un-premultiplied blend": {
    color: {
      operation: "add",
      srcFactor: "src-alpha",
      dstFactor: "one-minus-src-alpha",
    },
  },
  "destination-over": {
    color: {
      operation: "add",
      srcFactor: "one-minus-dst-alpha",
      dstFactor: "one",
    },
  },
  "source-in": {
    color: {
      operation: "add",
      srcFactor: "dst-alpha",
      dstFactor: "zero",
    },
  },
  "destination-in": {
    color: {
      operation: "add",
      srcFactor: "zero",
      dstFactor: "src-alpha",
    },
  },
  "source-out": {
    color: {
      operation: "add",
      srcFactor: "one-minus-dst-alpha",
      dstFactor: "zero",
    },
  },
  "destination-out": {
    color: {
      operation: "add",
      srcFactor: "zero",
      dstFactor: "one-minus-src-alpha",
    },
  },
  "source-atop": {
    color: {
      operation: "add",
      srcFactor: "dst-alpha",
      dstFactor: "one-minus-src-alpha",
    },
  },
  "destination-atop": {
    color: {
      operation: "add",
      srcFactor: "one-minus-dst-alpha",
      dstFactor: "src-alpha",
    },
  },
  "additive (lighten)": {
    color: {
      operation: "add",
      srcFactor: "one",
      dstFactor: "one",
    },
  },
} as const;

export const kPresets = keysOf(presets);
export type Preset = (typeof kPresets)[number];

export const color: GPUBlendComponent = {
  operation: "add",
  srcFactor: "one",
  dstFactor: "one-minus-src",
};

export const alpha: GPUBlendComponent = {
  operation: "add",
  srcFactor: "one",
  dstFactor: "one-minus-src",
};

export const constant = {
  color: [1, 0.5, 0.25],
  alpha: 1,
};

export const clear = {
  color: [0, 0, 0],
  alpha: 0,
  premultiply: true,
};

export const operations = ["add", "subtract", "reverse-subtract", "min", "max"];

export const factors = [
  "zero",
  "one",
  "src",
  "one-minus-src",
  "src-alpha",
  "one-minus-src-alpha",
  "dst",
  "one-minus-dst",
  "dst-alpha",
  "one-minus-dst-alpha",
  "src-alpha-saturated",
  "constant",
  "one-minus-constant",
];